<?php
class UsersController extends AppController {

	public function login() {
	
		if ( $this->Session->check('User') ) {	
				$this->redirect(array(
					'controller' => 'pages',
					'action' => 'home'
				));
		}

		//$this->layout = 'login';
	
		if ( $this->request->is('post') ){
		
			$user = $this->User->findByEmailAndPassword($this->request->data('User.email'),$this->request->data('User.password'));
			
			if( $user ) {
			
				$this->Session->write('User', $user);
				$this->redirect(array(
					'controller' => 'pages',
					'action' => 'home'
				));
			
			}
			
			$this->Session->setFlash('Email and password combindation are not correct.');
			
		}
	
	}
	
	public function logout() {

		$this->Session->destroy('User');
		$this->redirect(array(
			'controller' => 'pages',
			'action' => 'home'
		));

	}
	
	public function register() {
		
		if ( $this->Session->check('User') ) {	
				$this->redirect(array(
					'controller' => 'pages',
					'action' => 'home'
				));
		}	
		
	}

}
?>